package com.huazi.www.drug.drugy.servlet;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;

/**
 * 监听器
 * 生成处方单号
 *
 * @author 波——最帅的男人
 * @version 1.0
 * @date 2021/5/10 15:32
 */
public class RequestListener implements ServletRequestListener {
    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        Object user = sre.getServletContext().getAttribute("count");
        int num = 0;
        if (user != null) {
            num = Integer.parseInt(user.toString());
        }
        num++;
        sre.getServletContext().setAttribute("count", num);
    }

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        System.out.println("当前访问次数:" + sre.getServletContext().getAttribute("count"));
    }
}
